<%@ Page Language="C#" AutoEventWireup="true" Codebehind="ChapterAdmin.aspx.cs" errorPage="~/Error.aspx" Inherits="SecurityLinkUp.Admin.ChapterAdmin" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register Assembly="PietschSoft.VE" Namespace="PietschSoft.VE" TagPrefix="PietschSoftVE" %>
<html>
<body>

    <script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=5"></script>

    <script type="text/javascript">    
      //Sys.Application.add_load(GetChapterMap);   
      var ChapterMap = null;      
      
      function GetChapterMap()
      {
        ChapterMap = new VEMap('Map'); 
        ChapterMap.SetDashboardSize(VEDashboardSize.Tiny); 
        ChapterMap.LoadMap(new VELatLong(0,0), 0, 'r', false,VEMapMode.Mode2D, false);
        // resize is required in this instance to force the map to size correctly on the page
        ChapterMap.Resize(400,400);
      } 
  
      function FindChapterLocation (loc)
      {
        try
        {
            var loc = document.getElementById("ChapterGeoArea").value;
        
            if (loc != "")
            {
                GetChapterMap();
                var resultslayer = new VEShapeLayer();
                ChapterMap.AddShapeLayer(resultslayer);
                ChapterMap.Find('', loc, VEFindType.Businesses, resultslayer, 0, 5, true, true, false, true, ProcessChapterResults);
             }
        }
        catch (e)
        {
            alert(e.message);
        }
      }              
                
      
      function ProcessChapterResults(layer, findResults, places, hasmore)
      {
            for (resultID in places)
            {                
                var latitude = places[resultID].LatLong.Latitude;
                var longitude = places[resultID].LatLong.Longitude;                
                AddPushpin(resultID, latitude, longitude, places[resultID].Name, GenerateChapterDescription(latitude, longitude));
            }
      }
      
      function AddPushpin(pinId, latitude, longitude, title, details)
      {
        var vell = new VELatLong(latitude, longitude);
        var pp = new VEPushpin(pinId, vell, null , title, details, 'pushpin');
        ChapterMap.AddPushpin(pp);       
      } 
      
      function GenerateChapterDescription(Lat, Long)
      {
           var link = '<a href=\"javascript:SetChapterLatLongValues(\'';           
           link +=Lat;
           link +='\', \'';
           link +=Long;
           link +='\')\"> Set this point as location </a>';
           return link;
      }
      
      function SetChapterLatLongValues(Lat, Long)
      {
         document.getElementById("GeoLat").value = Lat;
         document.getElementById("GeoLong").value = Long;
         document.getElementById("ChapterLocationStatusImg").src = "/images/check.png"; 
      }

    </script>

    <form id="Form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel" runat="server">
            <ContentTemplate>
                <asp:Label ID="ChapterSelectLbl" runat="server" Text="Chapters I Admin"></asp:Label>&nbsp;<asp:DropDownList
                    ID="ChapterSelect" runat="server" Width="265px" AutoPostBack="True" OnSelectedIndexChanged="ChapterSelect_SelectedIndexChanged">
                </asp:DropDownList>&nbsp;
                <asp:CheckBox ID="AdminModeChk" runat="server" AutoPostBack="True" OnCheckedChanged="AdminModeChk_CheckedChanged"
                    Text="Set Admin Mode" Visible="False" />
                <br />
                <table cellpadding="5" style="width: 900px">
                    <tr>
                        <td valign="top" style="width: 110px">
                            Chapter Name</td>
                        <td style="width: 194px" valign="top">
                            <asp:TextBox ID="ChapterName" runat="server" Width="195px"></asp:TextBox></td>
                        <td rowspan="9" style="width: 421px" valign="top">
                            <PietschSoftVE:Map runat="server" ID="Map" Width="400" Height="400" Zoom="0" Latitude="20.0"
                                Longitude="10.0" ShowDashboard="False" />
                            <asp:HiddenField ID="GeoLat" runat="server" />
                            <asp:HiddenField ID="GeoLong" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td valign="top" style="width: 110px">
                            Parent Community</td>
                        <td style="width: 194px" valign="top">
                            <asp:DropDownList ID="ParentCommunity" runat="server" Width="202px">
                            </asp:DropDownList>
                            <cc1:ListSearchExtender ID="ParentCommunityListSearchExtender" runat="server" TargetControlID="ParentCommunity"
                                PromptPosition="Bottom" Enabled="True">
                            </cc1:ListSearchExtender>
                            &nbsp;<br />
                        </td>
                    </tr>
                    <tr>
                        <td valign="top" style="width: 110px">
                            Description<br />
                            <small>[Describe what this community is/does]</small>
                        </td>
                        <td style="width: 194px" valign="top">
                            <asp:TextBox ID="ChapterDescritpion" runat="server" Rows="4" TextMode="MultiLine"
                                Width="200px"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 110px" valign="top">
                            Status</td>
                        <td style="width: 194px" valign="top">
                            <asp:DropDownList ID="StatusList" runat="server" Width="207px">
                            </asp:DropDownList></td>
                    </tr>
                    <tr>
                        <td valign="top" style="width: 110px">
                            Status Notes<br />
                            <small>[Reasons/justifications given for the current status]</small></td>
                        <td style="width: 194px" valign="top">
                            <asp:TextBox ID="ChapterReason" runat="server" Rows="4" TextMode="MultiLine" Width="199px"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td valign="top" style="width: 110px">
                            Geographic Area<br />
                            <small>[Geographic region where this chapter operates - optional]</small></td>
                        <td style="width: 194px" valign="top">
                            <asp:TextBox ID="ChapterGeoArea" runat="server" Width="159px"></asp:TextBox>
                            <input type="button" id="FindChapterBtn" value="Find" onclick="FindChapterLocation()" />
                        </td>
                    </tr>
                    <tr>
                        <td valign="top" style="width: 110px">
                            Location Encoded
                        </td>
                        <td style="width: 194px" valign="top">
                            <asp:Image ID="ChapterLocationStatusImg" ImageUrl="~/Images/cross.png" runat="server"
                                ImageAlign="Top" />
                            <div>
                                <small>[Hover over map pins to set location]</small></div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <asp:Label ID="ChapterErrorMessage" CssClass="ErrorMessage" runat="server"></asp:Label></td>
                    </tr>
                    <tr>
                        <td colspan="2" align="right">
                            <asp:Button ID="DeleteBtn" runat="server" Text="Delete" Visible="False" />&nbsp;
                            &nbsp;<asp:Button ID="EditChapterBtn" runat="server" Text="Save Changes" OnClick="SaveChapterBtn_Click" /></td>
                    </tr>
                </table>
                <br />
                <cc1:ModalPopupExtender ID="DeletePopup" runat="server" TargetControlID="DeleteBtn"
                    PopupControlID="DeletePopupPanel" BackgroundCssClass="modalBackground" OkControlID="ConfirmDeleteBtn"
                    CancelControlID="CancelBtn" DropShadow="false" />
                <br />
                <asp:Panel ID="DeletePopupPanel" CssClass="WarningPopup" Style="display: none;" runat="server"
                    Width="350px">
                    <p>
                        Are you sure you want to delete this chapter?</p>
                    <p>
                        Usually, a chapter can be set to "INACTIVE" to keep it in the database but not shown
                        to users until one is <b>absolutly</b> sure it should be deleted.</p>
                    <p>
                        Continue to delete anyway?</p>
                    <div style="text-align: center">
                        <asp:Button ID="ConfirmDeleteBtn" runat="server" Text="Delete" OnClick="ConfirmDeleteBtn_Click" />&nbsp;
                        <asp:Button ID="CancelBtn" runat="server" Text="Cancel" />
                    </div>
                </asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>
